package com.chenchao.designer.simplefactory;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/14 12:28
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javadesigner.Factor.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 简单工厂模式
 * 把对象的创建细节隐藏起来，通过工厂直接获取对象
 * 优点：简单
 * 缺点：新增产品要修改参数判断逻辑，违反开闭原则
 * 特点：所有产品共有一个工厂
 */
public class Factory {
    public Fruite createFruite(String fruite){
        if ("apple".equals(fruite)){
            return new AppleImpl();
        }
        else if("pear".equals(fruite)){
            return  new PearImpl();
        }
        else {
            return null;
        }
    }
}
class Test{
    public static void main(String[] args) {
        Factory factory = new Factory();
        Fruite apple = factory.createFruite("apple");
        apple.show();
    }
}
